package com.example.attendancesystem_1_8;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.provider.ContactsContract;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends AppCompatActivity implements  View.OnClickListener{

    //定义四个布局(打卡，联系人，功能，个人中心)
    private Fragment mtab01 = new DakaFragment();
    private Fragment mtab02 = new CntFragment();
    private Fragment mtab03 = new FuncFragment();
    private Fragment mtab04 = new PersonalFragment();
    private Fragment mtab05 = new SetTimeFragment();
    //动态的添加、替换、移除某个Fragment
    private FragmentManager fm;
    //bottom中的四个线性布局
    private LinearLayout id_tab_1;
    private LinearLayout id_tab_2;
    private LinearLayout id_tab_3;
    private LinearLayout id_tab_4;
    //四个图像按钮
    private ImageButton imageButton_daka;
    private ImageButton imageButton_lianxi;
    private ImageButton imageButton_gongneng;
    private ImageButton imageButton_geren;
    //这行代码我也不懂
    private static final String TAG = Adapter.MyViewHolder.class.getSimpleName();
    private List<String> mList = new ArrayList<>();
    //打卡界面控件
    private Button button_face;
    private Button button_location;
    private CheckBox checkBox_face;
    private CheckBox checkBox_location;
    private Button button_normal;
    private Button button_outside;




    @SuppressLint("WrongViewCast")  //我也不懂
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main2);
        //btClientSingle = findViewById(R.id.button_Location);


        //tvResultSingle = findViewById(R.id.tv_result1);

        initview();
        initFragment();
        //initEvent();
        selectFragment(4);

        imageButton_daka.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                selectFragment(4);
            }
        });
        imageButton_lianxi.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                selectFragment(1);
            }
        });
        imageButton_gongneng.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                selectFragment(2);
            }
        });
        imageButton_geren.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                selectFragment(3);
            }
        });

    }



    //向MainActivity的FrameLayout中放入tab1...4
    private void initFragment()
    {
        fm = getSupportFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        //向MainActivity的FrameLayout中放入tab1...4
        transaction.add(R.id.id_content, mtab01);
        transaction.add(R.id.id_content, mtab02);
        transaction.add(R.id.id_content, mtab03);
        transaction.add(R.id.id_content, mtab04);
        transaction.add(R.id.id_content, mtab05);
        transaction.commit();
    }

    //初始化View
    @SuppressLint("WrongViewCast")
    private void initview()
    {
        id_tab_1 = findViewById(R.id.id_tab_1);
        id_tab_2 = findViewById(R.id.id_tab_2);
        id_tab_3 = findViewById(R.id.id_tab_3);
        id_tab_4 = findViewById(R.id.id_tab_4);

        imageButton_daka = findViewById(R.id.imageButton_daka);
        imageButton_lianxi = findViewById(R.id.imageButton_lianxi);
        imageButton_gongneng = findViewById(R.id.imageButton_gongneng);
        imageButton_geren = findViewById(R.id.imageButton_geren);


        Adapter adapter = new Adapter(this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        adapter.setVerticalDataList(mList);
    }

    //初始化底部按钮
/*
    private void initEvent()
    {
        imageButton_daka.setOnClickListener(this);
        imageButton_lianxi.setOnClickListener(this);
        imageButton_gongneng.setOnClickListener( this);
        imageButton_geren.setOnClickListener(this);
    }

 */


    //隐藏Fragment
    private void hidefragment(FragmentTransaction transaction)
    {
        transaction.hide(mtab01);
        transaction.hide(mtab02);
        transaction.hide(mtab03);
        transaction.hide(mtab04);
        transaction.hide(mtab05);
    }

    //选择某个界面——即按下按钮后的反应
    private void selectFragment(int i)
    {
        System.out.println("i-----" + i);
        FragmentTransaction transaction = fm.beginTransaction();
        hidefragment(transaction);
        switch (i)
        {
            case 0:
                transaction.show(mtab01);
                break;
            case 1:
                transaction.show(mtab02);
                break;
            case 2:
                transaction.show(mtab03);
                break;
            case 3:
                transaction.show(mtab04);
                break;
            case 4:
                transaction.show(mtab05);
            default:
                break;
        }
        transaction.commit();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.id_tab_1:
                selectFragment(0);
                break;
            case R.id.id_tab_2:
                selectFragment(1);
                break;
            case R.id.id_tab_3:
                selectFragment(2);
                break;
            case R.id.id_tab_4:
                selectFragment(3);
                break;
            default:
                break;
        }
    }



}